package com.yuanchu.store.controller;

import com.yuanchu.common.utils.R;
import com.yuanchu.store.dto.EditStoreParamsDto;
import com.yuanchu.store.dto.StoreDataDto;
import com.yuanchu.store.dto.StoreSalesDto;
import com.yuanchu.store.entity.YoshopStoreEntity;
import com.yuanchu.store.entity.YoshopStoreMenuEntity;
import com.yuanchu.store.entity.YoshopStoreRoleEntity;
import com.yuanchu.store.service.YoshopStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-02-26 16:39
 */
@Api(tags = "商家信息接口", description = "StoreController")
@RestController
public class StoreController {

    @Resource
    private YoshopStoreService storeService;
    Integer storeId = 10001;


    @ApiOperation("查询商家角色信息")
    @GetMapping("/role/list")
    public R queryStoreRoleList()
    {
        List<YoshopStoreRoleEntity> pageResult = storeService.queryStoreRoleList(storeId);
        return R.ok().put("data", pageResult);
    }

    @ApiOperation("查询商家菜单信息")
    @GetMapping("/menu/list")
    public R queryStoreMenuList()
    {
        List<YoshopStoreMenuEntity> pageResult = storeService.queryStoreMenuList(storeId);
        return R.ok().put("data", pageResult);
    }

    @Resource
    private YoshopStoreService yoshopStoreService;
    @GetMapping("/store/data")
    public R storeData() {
        StoreDataDto data = storeService.storeData();
        Map<String, Object> map = new HashMap<>();
        map.put("data", data);
        return R.ok().put("data", map);
    }
    @GetMapping("/store/info")
    public R storeInfo() {
        YoshopStoreEntity storeEntity = yoshopStoreService.queryStoreInfo(storeId);
        Map<String, Object> map = new HashMap<>();
        map.put("storeInfo", storeEntity);
        return R.ok().put("data", map);
    }

    @PostMapping("/store/update")
    public R updateStoreInfo(@RequestBody EditStoreParamsDto param) {
        boolean updated = yoshopStoreService.updateStoreInfo(param, storeId);
        if (updated) {
            return R.ok();
        }
        return R.error();
    }

    @GetMapping("statistics/data")
    public R statisticsData() {
        StoreSalesDto data = storeService.queryStatisticsData();
        Map<String, Object> map = new HashMap<>();
        map.put("data", data);
        return R.ok().put("data", map);
    }

}
